<template>
	<view class="container">
		<view class="im" @click="img">
			<image v-if="!flag" :src="'http://localhost:8090'+user.icon"
				style="width: 150rpx; height: 150rpx; border-radius: 50rpx;" mode=""></image>
		</view>

		<button type="default" v-if="flag" @click="login">登录</button>
		<uni-list v-if="!flag">
			<uni-list-item title="修改密码" note="" clickable @click="mima"></uni-list-item>
			<uni-list-item title="电话号码" :rightText="user.telephone" clickable @click="phone"></uni-list-item>
		</uni-list>
		<button type="default" v-if="!flag" @click="tui">退出登录</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				flag: true,
				user: {}

			}
		},
		methods: {
			phone(){
				uni.showToast({
					title: '您的号码:'+this.user.telephone,
					icon:'none'
				});
			}
			
			,
			mima(){
				uni.showToast({
					title: '功能暂未开发',
					icon:'none'
				});
			}
			
			,
tui(){
	uni.clearStorageSync('user')
	this.user={}
	this.flag=true
}

,
			login() {
				uni.navigateTo({
					url: "login/login"
				})
			},
			img() {

				uni.chooseImage({
					count: 1,
					success: (res) => {
						const tempFilePaths = res.tempFilePaths[0]
						const tempFiles = res.tempFiles[0]
						uni.uploadFile({
							url: 'http://localhost:8090/foodapp/uploadheadicon',
							formData: {
								id: this.user.id,

								file: tempFiles
							},
							// header:{"Content-Type": "form-data"},
							filePath: tempFilePaths,
							name: 'file',
							success: (res) => {

								let da = JSON.parse(res.data)

								this.user.icon = da.headiconpath

							},
							fail:(err)=>{
								
							},
							complete:(err)=>{
								
								if(err.statusCode!=200){
										uni.showToast({
									title: '请登录后再修改头像',
									icon:'none'
								});
								}
								
							
							}

						})
					}
				})
			}

		},
		onShow() {
			this.user = uni.getStorageSync('user')
			if(this.user.telephone!=null){
				this.flag=false
			}
		}
	}
</script>

<style>
	.container {
		padding: 20px;
		font-size: 14px;
		line-height: 24px;

	}

	.im {
		width: 150rpx;
		height: 150rpx;
		border-radius: 50rpx;
		background-color: #00ffff;
	}
</style>
